package com.zyfdroid.bigdialerkit;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import com.zyfdroid.bigdialerkit.utils.PermissionUtils;

public class InitializeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
    }

    private void showNotificationPermissionDialog() {
        new AlertDialog.Builder(this)
                .setTitle("需要通知访问权限")
                .setMessage("为了检测未接来电并更新小部件，请允许应用访问通知")
                .setPositiveButton("去设置", (dialog, which) -> openNotificationSettings())
                .setNegativeButton("取消", null)
                .show();
    }

    private void openNotificationSettings() {
        try {
            Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
            startActivity(intent);
        } catch (Exception e) {
            // 备用方案
            Intent intent = new Intent(Settings.ACTION_SETTINGS);
            startActivity(intent);
        }
    }

    public void btnAppDetail(View view) {
        PermissionUtils.showPermissionDialog(this);
    }

    public void btnNotification(View view) {
        showNotificationPermissionDialog();
    }
    private boolean isDefaultAssistant() {
        String currentService = Settings.Secure.getString(
                getContentResolver(),
                "voice_interaction_service"
        );
        return getPackageName().equals(currentService.split("/")[0]);
    }

    private void showSetupDialog() {
        new AlertDialog.Builder(this)
                .setTitle("设置助手")
                .setMessage("请将该程序设为默认数字助理以使用侧面按钮功能")
                .setPositiveButton("去设置", (d, w) -> openAssistantSettings())
                .setNegativeButton("取消", null)
                .show();
    }

    private void openAssistantSettings() {
        Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS);
        startActivity(intent);
    }
    public void btnAssistant(View view) {
        showSetupDialog();
    }
}
